<%@page contentType="text/html;charset=UTF-8" language="java" %>
<%@page import="java.sql.*" %>
<%
  request.setCharacterEncoding("utf-8");
  String StuNo = request.getParameter("stuid");
  String stuName = request.getParameter("stuname");
  String stuBirthday = request.getParameter("stubirthday");
  String stuSex = request.getParameter("stusex");
  String stuPoliticalStatus = request.getParameter("stupoliticalstatus");
  String stuIdentityCard = request.getParameter("studentitycard");
  String stuSpeciality = request.getParameter("stuspeciality");
  String stuAddress = request.getParameter("stuaddress");
  String stuPostCode = request.getParameter("stupostcode");
  String stuTelephone = request.getParameter("stutelephone");
  String stuEmail = request.getParameter("stuemail");

  Connection conn = null;
  Statement statement = null;
  ResultSet rs = null;

  try {
    Class.forName("com.mysql.jdbc.Driver");
    String dbName = "student";
    String userName = "root";
    String userPassword = "123456";
    String url = "jdbc:mysql://172.21.32.100/" + dbName + "?user=" + userName +
            "&password=" + userPassword + "&useUnicode=true&characterEncoding=utf-8";
    conn = DriverManager.getConnection(url);
    statement = conn.createStatement();
    if (StuNo != null && !StuNo.isEmpty()) {
      String sql = "INSERT INTO student(stu_no, stu_name, stu_sex, stu_politicalstatus, " +
              "stu_birthday, stu_identitycard, stu_speciality, stu_address, " +
              "stu_postcode, stu_telephone, stu_email) VALUES('" + StuNo + "','" +
              stuName + "','" + stuSex + "','" + stuPoliticalStatus + "','" +
              stuBirthday + "','" + stuIdentityCard + "','" + stuSpeciality + "','" +
              stuAddress + "','" + stuPostCode + "','" + stuTelephone + "','" +
              stuEmail + "')";
    }

  String sql = "SELECT * FROM student";
  rs = statement.executeQuery(sql);
%>


<html>
<head>
  <title>学生信息管理系统</title>
</head>
<body>
<table border="1" style="width:100%">
  <tr>
    <th colspan="7" style="font-size: x-large; text-align: center">学生信息表</th>
  </tr>
  <tr style="text-align: center">
    <th>学号</th>
    <th>姓名</th>
    <th>性别</th>
    <th>政治身份</th>
    <th>出生日期</th>
    <th>身份证号</th>
    <th>所在系部</th>
  </tr>
  <% while (rs.next()) { %>
  <tr style="text-align: center">
    <td><%= rs.getString("stu_no") %></td>
    <td><%= rs.getString("stu_name") %></td>
    <td><%= rs.getString("stu_sex") %></td>
    <td><%= rs.getString("stu_politicalstatus") %></td>
    <td><%= rs.getString("stu_birthday") %></td>
    <td><%= rs.getString("stu_identitycard") %></td>
    <td><%= rs.getString("stu_speciality") %></td>
  </tr>
  <% } %>
</table>
</body>
</html>

<%
} catch(Exception e) {
%><script>alert('操作出错: <%= e.getMessage() %>');</script><%

    e.printStackTrace();
  } finally {
    if(rs != null) try { rs.close(); } catch(Exception e) {}
    if(statement != null) try { statement.close(); } catch(Exception e) {}
    if(conn != null) try { conn.close(); } catch(Exception e) {}
  }
%>